package org.example.utils;

import org.example.pojo.OperationLog;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

/*
* 日志相关
* */
public class LogInfoUtil {



    public static OperationLog getLogInfo(String msg,String data){
        //获取ThreadLocaUtil中的信息
        Map<String, Object> user = ThreadLocalUtil.get();
        //获取用户信息
        StringBuilder sb = new StringBuilder();
        //获取当前时间
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        sb.append("操作信息->").append("(" ).append(user.get("id")).append(")").append("姓名->").append(user.get("name")).append("---").append(msg).append("---理由->").append(data).append("时间->").append(time);
        OperationLog log = new OperationLog();
        log.setUserId(Integer.valueOf( user.get("id").toString()));
        log.setOperationType(true);
        log.setText(sb.toString());
        log.setCreateTime(new Date());
        return log;
    }
}
